/***************************************************************************
Name:		clientmanager.h
Autor:		Kevin Huber
Version:	0.5
Last Edit:      02.07.2009

Beschreibung:
Verwaltet die Client Objekte.
***************************************************************************/

#ifndef CLIENTMANAGER_H
#define CLIENTMANAGER_H

#include "client.h"
#include <QTcpSocket>
#include <QObject>
#include "console.h"
#include "sqlconnection.h"

class Console;
class Client;
class ChatHandler;
class SQLConnection;
class ClientManager : public QObject
{
    Q_OBJECT

public:
    ClientManager(QObject *parent = 0);  // Defaul-Konstrucktor
    ~ClientManager(); // Destrucktor

    inline unsigned int getClientsCount() { return connectedClients; }
    inline bool clientsConnected() { return connectedClients > 0 ? true : false; }

    inline Client *getClient(const quint32 &cId) { return m_firstClient ? m_firstClient->getClient(cId) : NULL; }
    inline Client *getClient(const QString &cName) { return m_firstClient ? m_firstClient->getClient(cName) : NULL; }
    void removeClient(const quint32 &cId, QString reason = "No Reason");
    void removeClient(Client *client, QString reason = "No Reason");

    Client *newClient(QTcpSocket *socket, Client_Status cStatus = unknown);

    inline Client *getFirstClient() { return m_firstClient; }

private slots:
    void on_ClientDisconnected(Client *client) { removeClient(client, "Client disconnected"); }
    void on_clientError(const QString &error);

private:
    quint16 connectedClients;
    Client *m_firstClient;
    Client *m_lastClient;
    Console m_console;
    SQLConnection *m_TunnelDatabase;
};

#endif // CLIENTMANAGER_H
